unit uSyncAT;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, RzRadGrp, RzLabel, ExtCtrls, RzPanel,
  RzButton, RzRadChk, ComCtrls;

type
  TAT_INFO = record
    JobTime: DWord;
    DaysOfMonth: DWord;
    DaysOfWeek: UCHAR;
    Flags: UCHAR;
    Command: PWideChar;
  end;

  PAT_INFO = ^TAT_INFO;
  NET_API_STATUS = LongInt;

  TfmSyncAT = class(TForm)
    Button1: TButton;
    RzCheckBox1: TRzCheckBox;
    RzGroupBox1: TRzGroupBox;
    RzLabel1: TRzLabel;
    RzCheckGroup1: TRzCheckGroup;
    DateTimePicker1: TDateTimePicker;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

function NetScheduleJobAdd(ServerName: PWideChar; Buffer: PAT_INFO; var JobID:
  PDWord): NET_API_STATUS; stdcall;

var
  fmSyncAT          : TfmSyncAT;

implementation

{$R *.dfm}
function NetScheduleJobAdd; external 'netapi32.dll ' name 'NetScheduleJobAdd';

procedure TfmSyncAT.Button1Click(Sender: TObject);
var
  ATInfo            : PAT_Info;
  jobid             : PDword;
  h, m, s, i        : Word;
  w                 : LongWord;
begin
  //  ShowMessage(Application.ExeName);
  //  Exit;
  {  getmem(atinfo, sizeof(TAt_info));
    getmem(jobid, sizeof(dword));
    h:=HourOf(DateTimePicker1.Time);
    m:=MinuteOf(DateTimePicker1.Time);
    s:=SecondOf(DateTimePicker1.Time);
    w:=0;
    for i:=0 to 6 do
       if RzCheckGroup1.ItemChecked[i] then
           w:=w+ 1 shl i  ;

    atinfo^.jobtime := h * 60 * 60 * 1000 + m * 60 * 1000; //miliseconds   from   midnight   to   3:15
    atinfo^.DaysOfMonth := 0;
    atinfo^.DaysOfWeek := w;
    atinfo^.command :=PWideChar(Application.ExeName+' BACK');
    atinfo^.flags := 1;

    if NetScheduleJobAdd(nil, atinfo, jobid) <> 2 then
      showmessage(IntToStr(jobid^));
    freemem(jobid);
    freemem(atinfo);   }
end;

end.

